//
//  PKView.m
//  MyLittleBrother
//
//  Created by speeda on 17/8/10.
//  Copyright © 2017年 speeda. All rights reserved.
//

#import "PKView.h"
#import "CoverView.h"

@interface PKView ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation PKView

+ (void)viewFormXib {

    [CoverView showCoverView];
    
    PKView *view = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil].firstObject;
    view.center = [UIApplication sharedApplication].keyWindow.center;
    view.backgroundColor = [UIColor whiteColor];
    view.alpha = 0.0;
    [[UIApplication sharedApplication].keyWindow addSubview:view];
    
    [UIView animateWithDuration:0.1 animations:^{
        view.alpha = 1.0;
    }];
    
    [view pkAnimation];
    
}


- (void)pkAnimation {

    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 0; i < 124; i++) {
        [arrayM addObject:[UIImage imageNamed:[NSString stringWithFormat:@"pk_00%03d.png",i]]];
    }
    //设置动画数组
    [self.imageView setAnimationImages:arrayM];
    //设置动画播放次数
    [self.imageView setAnimationRepeatCount:1];
    //设置动画播放时间
    [self.imageView setAnimationDuration:arrayM.count*0.05];
    //开始动画
    [self.imageView startAnimating];
    
    [self performSelector:@selector(setAnimationImages) withObject:nil afterDelay:self.imageView.animationDuration];
    
}


- (void)setAnimationImages {

    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 89; i < 124; i++) {
        [arrayM addObject:[UIImage imageNamed:[NSString stringWithFormat:@"pk_00%03d.png",i]]];
    }
    //设置动画数组
    [self.imageView setAnimationImages:arrayM];
    //设置动画播放次数
    [self.imageView setAnimationRepeatCount:0];
    //设置动画播放时间
    [self.imageView setAnimationDuration:arrayM.count*0.05];
    //开始动画
    [self.imageView startAnimating];
    
//    [self.imageView stopAnimating];
}



@end
